package com.example.springrabbitmqexamples.springrabbitmqexamples.mq.consumer;

import com.example.springrabbitmqexamples.springrabbitmqexamples.SpringRabbitmqExamplesApplication;
import com.example.springrabbitmqexamples.springrabbitmqexamples.config.RabbitMqConfig;
import com.example.springrabbitmqexamples.springrabbitmqexamples.model.User;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Description
 * @Author benjamin
 * @Date 2020/7/27 17:25
 * @Version
 */
@Component
@RabbitListener(queues = {RabbitMqConfig.queueName})
public class MqConsumerUser {

    @Autowired
    ObjectMapper objectMapper;


    @RabbitHandler
    public void consume(byte[] bytes) throws IOException {

        User user = objectMapper.readValue(bytes, User.class);


        System.out.println("mq consumer 3 ----->" + user);

        SpringRabbitmqExamplesApplication.latch.countDown();


    }

}
